import sys
import itertools

class Solution:
    def __init__(self):
        self.res = None

    def start(self, gs):
        self.gs = gs
        self.found = 0

    def possible_num(self, maps, x, y, g):
        p = [True] * 3
        for i in range(3):
            if maps[x][i] != '*':
                p[int(maps[x][i]) - 1] = False
        for i in range(3):
            if maps[i][y] != '*':
                p[int(maps[i][y]) - 1] = False
        for i in range(3):
            xp, yp = g[i]
            if maps[xp][yp] != '*':
                p[int(maps[xp][yp]) - 1] = False
        return p

    def output_res(self):
        for i in range(3):
            print(self.res[i])

    def shudu(self, maps):
        if '*' not in maps[0] and '*' not in maps[1] and '*' not in maps[2]:
            self.found += 1
            self.res = maps
            # print(maps)
            return 1
        for g in self.gs:
            for x, y in g:
                if maps[x][y] == '*':
                    pnum = self.possible_num(maps, x, y, g)
                    for i in range(3):
                        if pnum[i]:
                            map_copy = maps.copy()
                            map_copy[x] = maps[x][:y] + str(i + 1) + maps[x][(y + 1):]
                            # print(map_copy)
                            shudu_res = self.shudu(map_copy)
                            if self.found > 1:
                                # print(self.found)
                                return self.found
                    return self.found

if __name__ == "__main__":
    fp = sys.stdin
    # fp = open('./1.in')
    num = int(fp.readline())
    s = Solution()
    for i in range(num):
        # run num times
        maps = [fp.readline().strip() for _ in range(3)]
        gs = [[int(x) for x in fp.readline().strip().split()] for _ in range(3)]
        gts = [[(g[2*j], g[2*j + 1]) for j in range(3)] for g in gs]
        s.start(gts)
        res = s.shudu(maps)
        if res == 1:
            print("Unique")
            s.output_res()
        elif res > 1:
            print("Multiple")
        else:
            print("No")
